import { fileUpload } from "@/service/storage-situation";

export async function tencentCloud({ files: likeArrayFiles }: { files: any[] }): Promise<any> {
  const files = Array.from(likeArrayFiles);
  return new Promise((resolve, reject) => {
    const result: any[] = [];
    const upload = (file: any) => {
      let formData = new FormData();
      formData.append("file", file);
      fileUpload(formData, {})
        .then((res) => {
          console.log("res--", res);
          let fileUrls = res.data.data.fileUrls;
          try {
            result.push(fileUrls[0]);
            if (files.length) {
              upload(files.shift());
              return;
            }
            resolve(result);
          } catch (error) {
            reject(error);
          }
        })
        .catch(() => { });
    };
    upload(files.shift());
  });
}
